package com.shuqi.model.parse.parser;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.shuqi.model.bean.PayInfo;
import com.shuqi.model.bean.PayModelInfo;
import com.shuqi.model.parse.HandlerBase;

/**
 * 充值首页解析器
 * 
 * @author chenwei
 * 
 */
public class PayParser extends HandlerBase {

    private PayInfo payInfo;

    private PayModelInfo payModelInfo;

    @Override
    public Object getParsedData() {
        return payInfo;
    }

    @Override
    public void startDocument() throws SAXException {
        super.startDocument();
        payInfo = new PayInfo();
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes)
            throws SAXException {
        if (localName.equals("PayMode")) {
            payModelInfo = new PayModelInfo();
            payModelInfo.setModeId(isNull(attributes, "modeId"));
            payModelInfo.setType(isNull(attributes, "type"));
            payModelInfo.setPrivilege(isNull(attributes, "privilege"));
            payInfo.getPayModelInfos().add(payModelInfo);
        } else if (localName.equals("Hint")) {
            String hint = isNull(attributes, "info");
            payInfo.getHintsList().add(hint);
        } else if (localName.equals("Recharge")) {
            String value = attributes.getValue("balance");
            if (value != null && value != "") {
                payInfo.setBalance(Double.valueOf(value));
            }
            payInfo.setCode(isNull(attributes, "code"));
            payInfo.setMsg(isNull(attributes, "msg"));
        }
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        super.characters(ch, start, length);
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        super.endElement(uri, localName, qName);
    }

    @Override
    public void endDocument() throws SAXException {
        // TODO Auto-generated method stub
        super.endDocument();
    }
}
